programming4us
           
 
 
SQL Server

SQL Server 2008: SQL Server Web Services - Building Web Services (part 1)

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
1/2/2011 11:46:45 AM
Let’s delve right into the process of building a web service in SQL Server 2008.

The first step is to decide which data or T-SQL functionality to expose to the clients who will ultimately call the web methods.

For this first example, you should create the stored procedure shown in Listing 1, which returns a row of data from the AdventureWorks2008 sample database. The purpose is to reveal a few attributes of an employee, given his or her unique EmployeeId.

Listing 1. A Stored Procedure for Your First Web Service
use AdventureWorks2008
GO
CREATE PROC dbo.GetEmployeeBasics
(
@EmployeeId int
)
AS
SELECT
e.BusinessEntityID,
FirstName,
LastName,
e.JobTitle
FROM HumanResources.Employee e
JOIN Person.Person p ON
e.BusinessEntityID = p. BusinessEntityID
WHERE BusinessEntityID = @EmployeeId

To expose this procedure as a web method of your web service, you use the CREATE ENDPOINT T-SQL statement, which falls under the formal SQL category of Data Definition Language (DDL). An endpoint can be defined as simply an entity on one end of a connection over a communication protocol, such as HTTP. SOAP endpoints have an additional nickname: nodes. SOAP nodes consist of a SOAP sender and a SOAP receiver, following the request-response model.

To create a SOAP-based HTTP endpoint, you use the fairly complex T-SQL syntax shown in Listing 2.

Listing 2. CREATE ENDPOINT T-SQL Syntax
CREATE ENDPOINT EndPointName [ AUTHORIZATION login ]
STATE = { STARTED | STOPPED | DISABLED }
AS HTTP
(
PATH = 'url'
, AUTHENTICATION =( { BASIC | DIGEST | INTEGRATED | NTLM | KERBEROS }
[ ,...n ] )
, PORTS = ( { CLEAR | SSL} [ ,... n ] )
[ SITE = {'*' | '+' | 'webSite' },]
[, CLEAR_PORT = clearPort ]
[, SSL_PORT = SSLPort ]
[, AUTH_REALM = { 'realm' | NONE } ]
[, DEFAULT_LOGON_DOMAIN = { 'domain' | NONE } ]
[, RESTRICT_IP = { NONE | ALL } ]
[, COMPRESSION = { ENABLED | DISABLED } ]
[, EXCEPT_IP = ( { <4-part-ip> | <4-part-ip>:<mask> } [ ,...n ] )
)
FOR SOAP
(
[ { WEBMETHOD [ 'namespace' .] 'method_alias'
( NAME = 'database.owner.name'
[ , SCHEMA = { NONE | STANDARD | DEFAULT } ]
[ , FORMAT = { ALL_RESULTS | ROWSETS_ONLY } ]
)
} [ ,...n ] ]
[ BATCHES = { ENABLED | DISABLED } ]
[ , WSDL = { NONE | DEFAULT | 'sp_name' } ]
[ , SESSIONS = { ENABLED | DISABLED } ]
[ , LOGIN_TYPE = { MIXED | WINDOWS } ]
[ , SESSION_TIMEOUT = timeoutInterval | NEVER ]
[ , DATABASE = { 'database_name' | DEFAULT }
[ , NAMESPACE = { 'namespace' | DEFAULT } ]
[ , SCHEMA = { NONE | STANDARD } ]
[ , CHARACTER_SET = { SQL | XML }]
[ , MAX_SOAP_HEADERS_SIZE = { int | DEFAULT }]
)



Before running the examples that follow, you should create a dedicated Windows login to use in the authorization scheme; this user should own and be able to access the database objects you create. In the examples that follow, this user is indicated as MyDomain\SQLWebServicesClient. Replace this name with your own.

Listing 3 contains the endpoint creation DDL that exposes dbo.GetEmployeeBasics to its web consumers.

Listing 3. T-SQL for Creating a SQL Server Web Service Endpoint
CREATE ENDPOINT EPT_SQL2008UnleashedExamples
AUTHORIZATION [MyDomain\SQLWebServicesClient]
STATE = STARTED
AS HTTP
(
AUTHENTICATION = (INTEGRATED),
PATH = '/opensql/',
PORTS = (CLEAR, SSL),
CLEAR_PORT = 80,
SSL_PORT = 443,
SITE = '*',
COMPRESSION = ENABLED
)
FOR SOAP
(
WEBMETHOD 'urn:www-samspublishing-com:examples'.'WM_GetEmployeeBasics'
(
NAME = 'AdventureWorks2008.dbo.GetEmployeeBasics',
SCHEMA = STANDARD,
FORMAT = ALL_RESULTS
),
WSDL = DEFAULT,
BATCHES = DISABLED,
SCHEMA = STANDARD,
LOGIN_TYPE = WINDOWS,
SESSION_TIMEOUT = 120,
DATABASE = 'AdventureWorks2008',
NAMESPACE = 'urn:www-samspublishing-com:examples',
CHARACTER_SET = XML
)



In this listing, the name of the endpoint (EPT_SQL2008UnleashedExamples) immediately follows the keywords CREATE ENDPOINT.

Note

Using EPT_ as a prefix is a naming convention chosen to delineate endpoints from other types of user-created objects. Any valid database object name is acceptable here.


The endpoint name is also conveniently used to drop the endpoint from the server, as follows:

DROP ENDPOINT EPT_SQL2008UnleashedExamples

But don’t drop the endpoint until you’ve finished trying out all the examples!

One caveat when creating endpoints: if the server name, port, and path you choose are already reserved or in use by another application (such as IIS) on your server, you may need to call the new stored procedure sp_reserve_http_namespace. This procedure explicitly reserves the URL of your choosing with http.sys so that you may use it for your endpoints. Here’s an example:

EXEC sp_reserve_http_namespace N'http://localhost:80/opensql'

Next in the DDL, the AUTHORIZATION keyword is used to specify the name of the login (either of authorization type Windows or SQL Server) that owns the endpoint. You can change the name of the login later by using the ALTER AUTHORIZATION statement, as in the following example:

ALTER AUTHORIZATION ON ENDPOINT::EPT_SQL2008UnleashedExamples
TO MyDomain\SomeOtherUser
Next, the STATE keyword indicates the initial state of the endpoint.

Much as in Windows services, the possible states are STOPPED, STARTED, and DISABLED. (For security’s sake, STOPPED is the default.)

To change the state of any endpoint, you again invoke the ALTER ENDPOINT syntax. The following example stops the endpoint:

ALTER ENDPOINT EPT_SQL2008UnleashedExamples STATE = STOPPED

Again, don’t do this until you are done with the examples!

Other -----------------
- SQL Server 2008: SQL Server Web Services
- SQL Server 2008: SQL Server Service Broker - Related System Catalogs
- SQL Azure Backup Strategies (part 2)
- SQL Azure Backup Strategies (part 1) - Copying a Database
- SQL Server 2008: Troubleshooting SSB Applications with ssbdiagnose.exe
- SQL Server 2008: Service Broker Routing and Security
- Migrating Databases and Data to SQL Azure (part 9)
- Migrating Databases and Data to SQL Azure (part 8)
- Understanding Service Broker Constructs (part 5)
- Understanding Service Broker Constructs (part 4) - Creating the Conversation Initiator
- Migrating Databases and Data to SQL Azure (part 7)
- Migrating Databases and Data to SQL Azure (part 6) - Building a Migration Package
- Migrating Databases and Data to SQL Azure (part 5) - Creating an Integration Services Project
- Understanding Service Broker Constructs (part 3)
- Understanding Service Broker Constructs (part 2) - Creating Queues for Message Storage
- Understanding Service Broker Constructs (part 1) - Defining Messages and Choosing a Message Type
- SQL Server 2008 : SQL Server Service Broker - Designing a Sample System
- Migrating Databases and Data to SQL Azure (part 4) - Fixing the Script
- Migrating Databases and Data to SQL Azure (part 3) - Reviewing the Generated Script
- SQL Server 2008 : SQL Server Service Broker - Understanding Distributed Messaging
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us